package com.bjpowernode.mvc.model.result;

import com.bjpowernode.common.enums.RespCode;
import lombok.Data;

/**
 * 统一应答结果类
 */
@Data
public class CommonResult {

    private int code = 0;

    private String msg = "";

    private Object data = "";

    public CommonResult() {
    }

    public CommonResult(RespCode respCode) {
        this.code = respCode.getCode();
        this.msg = respCode.getMsg();
    }

    public CommonResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CommonResult(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public static CommonResult ok() {
        return new CommonResult(RespCode.OK);
    }

    public static CommonResult ok(Object data) {
        CommonResult commonResult = new CommonResult(RespCode.OK);
        commonResult.setData(data);
        return commonResult;
    }

    public static CommonResult warn() {
        return new CommonResult(RespCode.FAIL);
    }

    public static CommonResult warn(RespCode respCode) {
        return new CommonResult(respCode);
    }

    public static CommonResult warn(RespCode respCode, Object data) {
        CommonResult commonResult = new CommonResult(respCode);
        commonResult.setData(data);
        return commonResult;
    }
}
